import org.testng.Assert;

import java.awt.event.ActionEvent;

public void testSnakeHitsWall() {
    Board board = new Board();
    Snake snake = board.getSnake();
    // 假设蛇初始⽅向向右，将蛇移动到靠近右边界的位置

    for (int i = 0; i < board.getB_WIDTH() / board.getDOT_SIZE() - 2;
         i++) {
        board.actionPerformed(new ActionEvent(this,
                ActionEvent.ACTION_PERFORMED, null));
    }
    // 再次移动，蛇应撞墙
    board.actionPerformed(new ActionEvent(this,
            ActionEvent.ACTION_PERFORMED, null));
    Assert.assertFalse(snake.isAlive(), "蛇撞墙后应该死亡。");
}
public void testSnakeHitsItself() {
    Board board = new Board(10);
    Snake snake = board.getSnake();
    // 模拟操作使蛇形成⼀个圈并撞到⾃身
    changeDirectionAndMove(board, Snake.Direction.DOWN);
    changeDirectionAndMove(board, Snake.Direction.LEFT);
    changeDirectionAndMove(board, Snake.Direction.UP);
    // 检查蛇是否撞到⾃⼰
    Assert.assertFalse(snake.isAlive(), "蛇撞到⾃身后应该死亡。");
}
private void changeDirectionAndMove(Board board, Snake.Direction
        newDirection) {
    board.getSnake().setCurrentDirection(newDirection);
    board.actionPerformed(new ActionEvent(this,
            ActionEvent.ACTION_PERFORMED, null));
}

public void main() {

}
